﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyThietBi.DAL.Models;

namespace QuanLyThietBi.DAL
{
    public class LichSuThietBiDAO
    {
        public int SaveLichSuThietBi(LICHSUTHIETBI tb)
        {
            try
            {
                using (var en = new QuanLyThietBiEntities())
                {
                    en.LICHSUTHIETBIs.AddObject(tb);
                    return en.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public List<LICHSUTHIETBI> GetAllLichSuThietBi(int thietbiId)
        {
            List<LICHSUTHIETBI> lichsuthietbi = null;
            try
            {
                using (var en = new QuanLyThietBiEntities())
                {
                    var ds = from lstb in en.LICHSUTHIETBIs
                             where lstb.id_thiet_bi == thietbiId
                             select lstb;
                    if (ds != null)
                    {
                        lichsuthietbi = ds.ToList();
                        //dsLoaiTB = ds.ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return lichsuthietbi;
        }

        //public LICHSUTHIETBI GetLichSuThietBi(int thietbiId)
        //{
        //    LICHSUTHIETBI lstb = new LICHSUTHIETBI();
        //    try
        //    {
        //        using (var en = new QuanLyThietBiEntities())
        //        {
        //            var dslstb = from ls_tb in en.LICHSUTHIETBIs
        //                         where ls_tb.id_thiet_bi == thietbiId
        //                         select ls_tb;

        //            if (dslstb != null)
        //            {
        //                lstb = dslstb.FirstOrDefault();
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //    return lstb;
        //}
    }
}
